
#include <BRender>
#include <BMaterial>
#include <BState>
#include <BConeShape>

using namespace BWE;

BConeShape::BConeShape(float radius, float height)
{
	_radius = radius;
	_height = height;
}
BConeShape::~BConeShape()
{

}

Shape BConeShape::type() const
{
	return Shape_Cone;
}

void BConeShape::setRadius(float radius)
{
	if (_radius != radius)
	{
		_radius = radius;
		dirtyBound();
	}
}
float BConeShape::radius() const
{
	return _radius;
}

void BConeShape::setHeight(float height)
{
	if (_height != height)
	{
		_height = height;
		dirtyBound();
	}
}
float BConeShape::height() const
{
	return _height;
}

void BConeShape::bound(BBoundingBox& bbox) const
{
	bbox.setCenter(BVector(0, 0, _height / 2));
	bbox.setLenA(_radius);
	bbox.setLenB(_radius);
	bbox.setLenC(_height / 2);
}
void BConeShape::render(BRender& render)
{
	render.setLighting(false);
	render.setColor(0, 1, 0.1, 0.42);
	float coses[24];
	float sines[24];
	for (int i = 0; i < 24; i++)
	{
		double angle = i * PI2 / 24;
		coses[i] = cos(angle);
		sines[i] = sin(angle);
	}
	for (int i = 0; i < 24; i++)
	{
		int next = (i + 1) % 24;
		BVector a(coses[i] * _radius, sines[i] * _radius, 0);
		BVector b(coses[next] * _radius, sines[next] * _radius, 0);
		BVector c(0, 0, _height);
		render.drawTriangle(a, b, c);
	}
}
